using System;

namespace Conusic
{
    public sealed class VkApiException : Exception
    {
        private readonly int _errorCode;
        private readonly string _errorMsg;

        public VkApiException(int errorCode, string errorMsg)
        {
            _errorCode = errorCode;
            _errorMsg = errorMsg;
        }

        public override string ToString()
        {
            return String.Format("VkApi exception #{0}: {1}", _errorCode, _errorMsg);
        }
    }

    [Serializable]
    public sealed class CaptchaException : ApplicationException
    {
    }

    [Serializable]
    public sealed class WrongUserNameOrPassword : ApplicationException
    {
    }

    [Serializable]
    public sealed class SavedCookieErrorException : ApplicationException
    {
    }

    [Serializable]
    public sealed class GraffitiUploadException : Exception
    {
    }

    [Serializable]
    // TODO: Normalize exception output form 
    internal class ParseException : ApplicationException
    {
        private readonly string _page;
        private readonly string description = String.Empty;

        public ParseException(string message)
            : base(message)
        {
            description = String.Format("Parse Exception: {0}", message);
        }

        public ParseException()
        {
            description = "Parsing exception";
        }

        public ParseException(string canNotFindIpHash, string page)
        {
            _page = page;
        }

        public override string ToString()
        {
            return description;
        }
    }

    [Serializable]
    internal sealed class ParseHashFailException : ParseException
    {
        private readonly string page;

        public ParseHashFailException(string page)
        {
            this.page = page;
        }

        public override string ToString()
        {
            return string.Format("[ParseHashFailException Page={0}]", page);
        }
    }

    [Serializable]
    internal sealed class ParseMediaIdFailException : ParseException
    {
        private readonly string page;

        public ParseMediaIdFailException(string page)
        {
            this.page = page;
        }

        public override string ToString()
        {
            return string.Format("[ParseMediaIdFailException Page={0}]", page);
        }
    }
}
